package cn.stylefeng.guns.modular.transport.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportAuditProcess;
import cn.stylefeng.guns.modular.transport.mapper.TransportAuditProcessMapper;
import cn.stylefeng.guns.modular.transport.model.params.TransportAuditProcessParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportAuditProcessResult;
import  cn.stylefeng.guns.modular.transport.service.TransportAuditProcessService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 审核流程表 服务实现类
 * </p>
 *
 * @author like
 * @since 2024-10-15
 */
@Service
public class TransportAuditProcessServiceImpl extends ServiceImpl<TransportAuditProcessMapper, TransportAuditProcess> implements TransportAuditProcessService {

    @Override
    public void add(TransportAuditProcessParam param){
        TransportAuditProcess entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TransportAuditProcessParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TransportAuditProcessParam param){
        TransportAuditProcess oldEntity = getOldEntity(param);
        TransportAuditProcess newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TransportAuditProcessResult findBySpec(TransportAuditProcessParam param){
        return null;
    }

    @Override
    public List<TransportAuditProcessResult> findListBySpec(TransportAuditProcessParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TransportAuditProcessParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TransportAuditProcessParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TransportAuditProcess getOldEntity(TransportAuditProcessParam param) {
        return this.getById(getKey(param));
    }

    private TransportAuditProcess getEntity(TransportAuditProcessParam param) {
        TransportAuditProcess entity = new TransportAuditProcess();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
